<template>
	<view class="content an-sign">
		<view class="an-search" v-show="searchShow">
			<uni-search-bar radius="100" clearButton="auto" placeholder="用户名搜索" @confirm="search" @cancel="cancel"/>
		</view>
		<uni-list>
			<uni-list-item v-for="item in list" :key="item.id"
			@tap="clickList(item)"
			:title="item.nickname" 
			:note="item.logintime" 
			:thumb="item.avatarurl" />
		</uni-list>
		<uni-load-more :loadingType="loadingType"></uni-load-more>
	</view>
</template>

<script>
	import uniList from '@/components/uni-list/uni-list.vue'
	import uniListItem from '@/components/uni-list-item/uni-list-item.vue'
	import uniLoadMore from '@/components/uni-load-more.vue'
	import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
	export default {
		components: {
			uniList,
			uniListItem,
			uniLoadMore,
			uniSearchBar
		},
		data() {
			return {
				postData:{
					page:1,
					pageSize: 10,
					nickname:'',	// 用户名
					gender:''		// 性别
				},
				list:[],
				total:0,
				loadingType: 0, //上拉的状态：0-loading前；1-loading中；2-没有更多了
				searchShow: false,	// 是否显示搜索框
			}
		},
		onReady(){
			this.getList(1)
		},
		onNavigationBarButtonTap(obj){	// 页面元素 右上角按钮触发
			this.searchShow = this.searchShow ? false : true
		},
		methods: {
			search(res) {	// 搜索组件回调
				this.postData.nickname = res.value
				this.getList(1)
			},
			cancel(){	// 搜索取消 
				this.postData.nickname = '' // 搜索项清空
				this.getList(1)
			},
			getList(page){
				this.loadingType = 1
				if(page){
					this.postData.page = page
				}
				if(this.postData.page === 1){
					this.list = []
				}
				this.$api.wxGetAllUser(this.postData).then(res=>{
					this.list.push(...res.list); 
					this.total = res.total
					this.loadingType = 0
				})
			},
			onReachBottom() {	// 页面到底 触发
				if (this.loadingType !== 0) {
					return;
				}
				if(Math.ceil(this.total/this.postData.pageSize)>this.postData.page && this.total != 0 ){
					this.postData.page += 1
					this.getList()
				}else{
					this.loadingType = 2
				}
			},
			clickList(item){
				uni.navigateTo({
					url: "../sign/signInfo?detailDate=" + encodeURIComponent(JSON.stringify(item))
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
